package com.hgkj.cloud.base.scheme.table;

import com.hgkj.cloud.base.scheme.ClsAnswerRequest;
import com.hgkj.cloud.base.scheme.ClsAnswerResult;
import com.hgkj.cloud.base.scheme.ClsScore;

import java.util.Map;

/**
 * 2: 瑞文高级推理测验（Rwgj）共36题
 */
public class Table2 extends AbstractTable implements TableCalculate{
    String code = "Rwgj";

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public ClsAnswerResult calc(ClsAnswerRequest answer) {
        return GetRwgjFactorScore(answer);
    }

    @Override
    public String[] report(Map map) {
        return GetRwgjReport(map);
    }

    private static ClsAnswerResult GetRwgjFactorScore(ClsAnswerRequest answer) {
        ClsAnswerResult result = new ClsAnswerResult();
        result.setMessage("");
        result.setType(answer.getType());
        result.setUuid(answer.getUuid());
        try {
            // 1正确题数
            int MAX_NUM = 36;
            // 题目的正确答案
            String strTemp = "5,1,7,4,3,1,6,1,8,4,5,6,2,1,2,4,6,7,3,8,8,7,6,3,7,2,7,5,6,5,4,8,5,1,3,2";
            String[] strAnswer_s = strTemp.split(",");

            int intI;
            String[] strAnswer_c = answer.getAnswer().split(g_sChar);
            if (strAnswer_c.length > 1) {
                for (intI = 1; intI < strAnswer_c.length; intI++) {
                    strAnswer_c[intI] = strAnswer_c[intI].trim();
                }
            }

            String[] sAnswer = strAnswer_c[0].split(g_nChar);

            if (sAnswer.length != MAX_NUM) {
                result.setMessage("答案数量不符！");
                return result;
            }

            int i;
            int vFactor = 0;

            // 原始分
            for (i = 0; i < sAnswer.length; i++) {
                if (sAnswer[i].equalsIgnoreCase(strAnswer_s[i])) {
                    vFactor += 1;
                }
            }

            ClsScore.Rwgj gjrw = new ClsScore.Rwgj();
            gjrw.setCorrectAmount_o(vFactor);

            result.setObject(gjrw);
            return result;
        } catch (ArithmeticException e) {
            result.setMessage(e.toString());
            return result;
        }
    }


    // 二、瑞文高级推理测验Rwgj
    private String[] GetRwgjReport(Map map) {
        // 下面因子名称字段改成.toLowerCase()小写，是因为JAVA转json的时候会把大写字母转成小写字母
        // 第一个，错误信息；第二个，量表得分部分；第三个，量表指导意见_d数组部分
        String[] strResult = { "", "", "", "", "" };
        // String[] strResult = {"","",""};
        try {
            if (g_inblFactor) // 因子得分
            {
                strResult[1] += "<table cellpadding='0' cellspacing='0' width='100%' border='0'>";

                strResult[1] += "<tr><td" + subTitle(0, tWidth * 2) + ">正确题数(共36题)</td>" + "<td" + subValue(0, -1) + ">"
                        + map.get("correctAmount_o") + "</td></tr>";

                strResult[1] += "</table>";
            }

            strResult[3] = "0";
            strResult[4] = "";

            return strResult;
        } catch (ArithmeticException e) {
            strResult[0] = "失败";
            return strResult;
        }
    }




}
